home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Shift Layout ƒ / QDGX shell misc.c next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  3.2 KB  |  156 lines  |  [TEXT/KAHL]

  1. /**\
  2. |**| =====================================================================
  3. |**|
  4. |**|    QDGX shell misc.c
  5. |**|
  6. |**|    This file contains utility and menu handling routines for
  7. |**|    the QuickDraw GX shell program.
  8. |**|
  9. |**|    ©1992-1994  Apple Computer, Inc.
  10. |**|    All rights reserved.
  11. |**|
  12. |**| =====================================================================
  13. \**/
  14.  
  15.  
  16. #include "QDGX shell.h"
  17.  
  18.  
  19. /**\
  20. |**| ---------------------------------------------------------------------
  21. |**| DoMenuCommand()
  22. |**| This routine handles the dispatching of our menu requests.
  23. |**| ---------------------------------------------------------------------
  24. \**/
  25. void DoMenuCommand (long menuResult)
  26. {
  27.     short                menuID;
  28.     short                menuItem;
  29.     Str255                daName;
  30.     OSErr                err;
  31.     gxDialogResult        result;
  32.     
  33.     menuID = menuResult >>16;
  34.     menuItem = menuResult & 0x0000ffff;
  35.     
  36.     switch (menuID)
  37.     {
  38.         case mApple:
  39.             switch (menuItem)
  40.             {
  41.                 case iAbout:                /* display About box */
  42.                     NoteAlert(rAboutBoxID,nil);
  43.                     break;
  44.                 
  45.                 default:                    /* handle DA selection */
  46.                     GetItem(GetMHandle(mApple), menuItem, daName);
  47.                     OpenDeskAcc(daName);
  48.                     break;
  49.             }
  50.             break;
  51.  
  52.  
  53.         case mFile:
  54.             switch (menuItem)
  55.             {                        
  56.                 case iNew:                    /* create new window */
  57.                     err = DoCreateNew();
  58.                     break;
  59.                                             
  60.                 case iOpen:                    /* open saved window */
  61.                     break;
  62.                                             
  63.                 case iClose:                /* close front window */
  64.                     DoDispose(FrontWindow());
  65.                     break;
  66.                                             
  67.                 case iSave:                    /* save front window */
  68.                     break;
  69.                                             
  70.                 case iPageSetup:            /* perform page setup */
  71.                     HiliteMenu(0);
  72.                     err = DoFormat(FrontWindow(), &result);
  73.                     break;
  74.                                             
  75.                 case iPrintOne:                /* perform print-one */
  76.                     err = DoPrintOne(FrontWindow());
  77.                     break;
  78.                     
  79.                 case iPrint:                /* perform print */
  80.                     HiliteMenu(0);
  81.                     err = DoPrinting(FrontWindow());
  82.                     break;
  83.  
  84.                 case iQuit:
  85.                     gQuitting = true;
  86.                     break;
  87.             }
  88.             break;
  89.  
  90.  
  91.         case mEdit:
  92.             break;
  93.     }
  94.     HiliteMenu(0);
  95. }
  96.  
  97.  
  98. /**\
  99. |**| ---------------------------------------------------------------------
  100. |**| GetDocShape()
  101. |**| This utility routine returns the page contents shape
  102. |**| attached to a window's document.
  103. |**| ---------------------------------------------------------------------
  104. \**/
  105. gxShape GetDocShape (WindowPtr wind)
  106. {
  107.     TH_Doc    doc;
  108.     gxShape    docPage = nil;
  109.  
  110.     if ( wind != NULL )
  111.     {
  112.         doc = (TH_Doc) GetWRefCon(wind);
  113.         docPage = (*doc)->docPage;
  114.     }
  115.     
  116.     return docPage;
  117. }
  118.  
  119.  
  120. /**\
  121. |**| ---------------------------------------------------------------------
  122. |**| GetDocJob()
  123. |**| This utility routine returns the print job attached to a window's document.
  124. |**| ---------------------------------------------------------------------
  125. \**/
  126. gxJob GetDocJob (WindowPtr wind)
  127. {
  128.     TH_Doc    doc;
  129.     gxJob        docJob = nil;
  130.  
  131.     if ( wind != NULL )
  132.     {
  133.         doc = (TH_Doc) GetWRefCon(wind);
  134.         docJob = (*doc)->docJob;
  135.     }
  136.     
  137.     return docJob;
  138. }
  139.  
  140.  
  141. /**\
  142. |**| ---------------------------------------------------------------------
  143. |**| MyStrLength()
  144. |**| This function takes the length of a C-style string quickly without
  145. |**| requiring an ANSI library to be linked in.
  146. |**| ---------------------------------------------------------------------
  147. \**/
  148. short MyStrLength (char *s)
  149. {
  150.     short len;
  151.  
  152.     for (len = 0; *s++ != 0; len++) ;
  153.     return len;
  154. }
  155.  
  156.